package common

import (
	"github.com/pkg/errors"
	"gopkg.in/yaml.v3"
	"io/ioutil"
)

type conf struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Password string `yaml:"password"`
	Dbname   string `yaml:"dbname"`
}

func GetConfig() (dbconf conf, err error) {
	dbconf = conf{}
	yamlfile, err := ioutil.ReadFile("./config/config.yml")
	if err != nil {
		return dbconf, errors.Wrap(err, "ERR: fail to read file")
	}
	err = yaml.Unmarshal(yamlfile, &dbconf)
	if err != nil {
		return dbconf, errors.Wrap(err, "ERR: fail to parse yaml")
	}
	return
}
